import { getStore } from '@/utils/store.js'
export function getlist(swaggerinfo, path, methodType) {
  const { list } = getStore({ name: 'swaggerconfig' })
  return getswaggerInfo(list, swaggerinfo, path, methodType)
}
export function getswaggerInfo(list, swaggerinfo, path, methodType) {
  const listpath = list.split('.')
  const OkResult = swaggerinfo.paths[path][methodType].responses['200'].schema
  if (OkResult !== undefined) {
      let resultvalue = getvalue(swaggerinfo, OkResult.$ref)
      if (resultvalue === undefined) {
          return null
      }
      for (let i = 0;i < listpath.length; i++) {
          resultvalue = resultvalue.properties[listpath[i]]
          if (resultvalue === undefined) {
              return null
          }
          if (resultvalue.items === undefined && i === (listpath.length - 1)) {
             return null
          } else if (resultvalue.items === undefined) {
            resultvalue = getvalue(swaggerinfo, resultvalue.$ref)
          } else {
              resultvalue = getvalue(swaggerinfo, resultvalue.items.$ref)
          }
      }
      if (resultvalue === undefined) {
          return null
      }
      return resultvalue
  }
  return null
}
export function getvalue(swaggerJsonInfo, jsonpath) {
  if (jsonpath === undefined) {
      return undefined
  }
  let paramvalue = {}
  const jsonpatharry = jsonpath.split('/')
  jsonpatharry.forEach(ee => {
      if (ee === '#') {
          paramvalue = swaggerJsonInfo
      } else {
          paramvalue = paramvalue[ee]
      }
  })
  return paramvalue
}
